import { transform } from "stream-transform";

// Generate a dataset of 5 records
const records = "record\n".repeat(5).trim().split("\n");
// Initialize the transformation
const transformer = transform(records, (record, callback) => {
  setTimeout(() => {
    const { running, started, finished } = transformer.state;
    callback(null, `${running}_${started}_${finished}\n`);
  }, 100);
});
// Get notify when done
transformer.on("end", () => {
  process.stdout.write("-------\n");
  const { running, started, finished } = transformer.state;
  process.stdout.write(`${running}_${started}_${finished}\n`);
});
// Print the transformed records to the standard output
transformer.pipe(process.stdout);
